package jjn.daily;

/**
 * @author Jiang Jining
 * @since 2023-07-22 23:21
 */
public class LeetCode860 {
    public boolean lemonadeChange(int[] bills) {
        int fiveCount = 0, tenCount = 0;
        for (int bill : bills) {
            if (bill == 5) {
                fiveCount++;
                continue;
            }
            if (bill == 10) {
                if (fiveCount == 0) {
                    return false;
                }
                fiveCount--;
                tenCount++;
                continue;
            }
            
            if (tenCount == 0) {
                if (fiveCount <= 2) {
                    return false;
                }
                fiveCount = fiveCount - 3;
                continue;
            }
            
            if (fiveCount < 1) {
                return false;
            }
            fiveCount--;
            tenCount--;
        }
        return true;
    }
    
    public static void main(String[] args) {
        int[] bills = new int[]{5, 5, 5, 5, 5, 5, 20, 5, 5, 20, 20, 5, 20, 5, 20, 20, 5, 20, 20, 5};
        boolean lemonadeChange = new LeetCode860().lemonadeChange(bills);
        System.out.println("lemonadeChange = " + lemonadeChange);
    }
}
